#include "thread.h"
int makeWork(threadPool_t *pThreadPool){
    for(int i = 0; i < pThreadPool->workNum; ++i){
        pthread_create(&pThreadPool->workArr[i],NULL,threadFunc,pThreadPool);
    }
    return 0;
}
void *threadFunc(void *arg){
    threadPool_t * pThreadPool = (threadPool_t *)arg;

    while(1){
        //userinfo_t userinfo;
        pthread_mutex_lock(&pThreadPool->mutex);
        while(pThreadPool->task.size == 0){
            pthread_cond_wait(&pThreadPool->cond,&pThreadPool->mutex);
        }
        printf("worker got a job!\n");
        int netfd = pThreadPool->task.pFront->netfd;
        outQueue(&pThreadPool->task);
        pthread_mutex_unlock(&pThreadPool->mutex);

        //checkUser(netfd,userinfo);

        dirID_t dirID;
        char testUser[]="user";
        creatDirID(testUser,&dirID);
        while(1){
            train_t train;
            int ret=recv(netfd,&train.status,sizeof(int),MSG_WAITALL);
            printf("%d\n",train.status);
            if(ret==0){
                break;
            }

            switch(train.status){
            case OD_CD:
                changeDir(&dirID,netfd);
                break;
            case OD_LS:
                myls(netfd,&dirID);
                break;
            case OD_MD:
                mkDir(&dirID,netfd);
                break;
            case OD_RD:
                rmDir(&dirID,netfd);
                break;
            case OD_RM:
                rm(netfd,&dirID);
                break;
            case OD_PWD:
                pwd(netfd,&dirID);
                break;
            }
        }

        //执行任务
    }
}
